package com.yochi.pictureseditor.tools;

import java.io.File;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;

public class UriUtils {

	public static final Uri convertMediaUriToFileUri(Context context, Uri uri) throws NullPointerException {
		Uri fUri = Uri.withAppendedPath(Uri.parse("file:"), File.separator+convertMediaUriToPath(context, uri));
		return fUri;
	}
	
	public static String convertMediaUriToPath(Context context, Uri uri) throws NullPointerException {
	    String [] proj={MediaStore.Images.Media.DATA};
	    Cursor cursor = context.getContentResolver().query(uri, proj,  null, null, null);
	    int column_index;
	    try {
	    	column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
	    } catch (NullPointerException e) {
	    	throw e;
	    }
	    cursor.moveToFirst();
	    String path = cursor.getString(column_index); 
	    cursor.close();
	    return path;
	}

	public static Uri getUriForPath(String path) {
		return Uri.fromFile(new File(path));
	}
	
}
